package com.lagou.service.Impl;

import com.lagou.base.Statuscode;
import com.lagou.dao.CourseDao;
import com.lagou.dao.Impl.CourseDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.utils.DateUtils;

import java.util.List;

public class CourseServiceImpl implements CourseService {
    @Override
    public List<Course> findCourseList() {
        CourseDao courseDao =new CourseDaoImpl();
        List<Course>courseList=courseDao.findCourseList();

        return courseList;
    }

    @Override
    public List<Course> findCourseNameAndStatus(String course_name, String status) {
        CourseDao CourseDao = new CourseDaoImpl();
       List<Course> result= CourseDao.findCourseNameAndStatus(course_name,status);

        return result;
    }

    @Override
    public String  SaveCourseSales(Course course) {

        //1.补全课程信息
        String dateFormart = DateUtils.getDateFormart();
        course.setCreate_time(dateFormart);
        course.setUpdate_time(dateFormart);
        course.setStatus(0);

        CourseDao courseDao = new CourseDaoImpl();
        int i = courseDao.SaveCourseSales(course);

        if (i > 0) {

            String result = Statuscode.SUCCESS.toString();
            return result;

        } else if (i < 0) {
            String result = Statuscode.FAIL.toString();
            return result;

        }

        return null;
    }

    @Override
    public List<Course> findCourseById(int id) {
        CourseDao courseDao = new CourseDaoImpl();
        List<Course> list = courseDao.findCourseById(id);
        return list;
    }

    }

